class Tag < ActiveRecord::Base
  has_many :taggings;
  has_many :podcasts, :through => :taggings, :source => :taggable, :source_type => "Podcast"
  has_many :episodes, :through => :taggings, :source => :taggable, :source_type => "Episode"

  validates_presence_of :name;
  validates_length_of :name, :within => 1..20;
  validates_uniqueness_of :name;
  
  # has_many :taggables, :through => :taggings;
  def taggables
    episodes + podcasts;
  end

  def has?(taggable)
    taggables.include?(taggable);
  end

end